package com.spring.future.modules.sys.web;

import com.google.common.collect.Lists;
import com.spring.future.common.utils.ObjectMapperUtils;
import com.spring.future.modules.sys.domain.Menus;
import com.spring.future.modules.sys.service.MenusService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Created by zh on 2017/1/15.
 */
@RestController
public class MenusController {
    @Autowired
    private MenusService menusService;

    @RequestMapping(value = "/weixin/getMenus")
    public String getMenus(String id){
        List<Menus> menusList = Lists.newArrayList();
        if(StringUtils.isEmpty(id)){
            menusList= menusService.findFirsy();
        }else{
            menusList = menusService.findByParentId(id);
        }
        return ObjectMapperUtils.writeValueAsString(menusList);
    }
}
